package com.peng.leetcode.swordoffer;

/**
 * Sword11MinArray
 * 剑指 Offer 11. 旋转数组的最小数字
 * https://leetcode.cn/problems/xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof/
 *
 * @author: lupeng6
 * @create: 2023/3/10 12:10
 */
public class Sword11MinArray {
    public static void main(String[] args) {
        System.out.println(new Sword11MinArray().minArray(new int[]{1, 1}));
    }

    public int minArray(int[] numbers) {
        int l = 0;
        int r = numbers.length - 1;
        while (l < r) {
            int mid = l + (r - l) / 2;
            if (numbers[l] == numbers[mid] && numbers[mid] == numbers[r]) {
                l++;
                r--;
            } else if (numbers[mid] <= numbers[r]) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        return numbers[l];
    }
}
